package com.egghiro.framework.j2se.game.model.element;

/**
 * 线速度2D 
 * @project SGame
 * @version 0.1
 */
public class LinearVelocity2D extends LinearVelocity {
    private double angleInDigree;

    public LinearVelocity2D(double speed, double angleInDigree) {
        super(speed);
        this.setAngleInDigree(angleInDigree);
    }
    /**
     * (As the +y is going down, same as Graphics)
     * @return
     */
    public double getAngleInDigree() {
        return angleInDigree;
    }

    public void setAngleInDigree(double angleInDigree) {
        angleInDigree = angleInDigree % 360;
        while (angleInDigree < 0) {
            angleInDigree += 360;
        }
        while (angleInDigree >= 360) {
            angleInDigree -= 360;
        }
        this.angleInDigree = angleInDigree;
    }
    /**
     * (As the +y is going down, same as Graphics)
     * @param angleInDigree <BR>
     *  if angleInDigree > 0, the velocity will turn clockwise.
     */
    public void turn(double angleInDigree) {
        double angle = this.angleInDigree + angleInDigree;
        setAngleInDigree(angle);
    }

    public int getDx() {
        return (int) (Math.round(getSpeed()
                * Math.cos(Math.toRadians(angleInDigree))));

    }
    /**
     * (As the +y is going down, same as Graphics)
     * @return
     */
    public int getDy() {
        return (int) (Math.round(getSpeed()
                * Math.sin(Math.toRadians(angleInDigree))));
    }
}
